/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.daubechiesfilter.statistics;

import com.compomics.util.experiment.massspectrometry.Spectrum;
import org.apache.commons.math.stat.descriptive.SummaryStatistics;

/**
 *
 * @author Kenneth
 */
public class SizeSampler {

    private static double z = 1.96;
    private static double s = 0.95;
    private static double N = 3000;
    private static double ME = 941.2;
    private static double n = 0;
    private static SummaryStatistics statistics = new SummaryStatistics();

    public SizeSampler(Spectrum spectrum) {
        double[] intensities = spectrum.getIntensityValuesAsArray();
        for (double anIntensity : intensities) {
            statistics.addValue(anIntensity);
        }
        this.s = statistics.getStandardDeviation();
        this.N = statistics.getN();
        this.ME = statistics.getMean();
    }

    public int calculateFrameSize() {
        n = ((z * z) * (s * s) * (N / (N - 1))) / ((ME * ME) + ((z * z) * (s * s) / (N - 1)));
        System.out.println("Population size : " + N);
        System.out.println("Z-score : " + z);
        System.out.println("Mean : " + ME);
        System.out.println("Stdev : " + s);
        System.out.println("-----------");
        System.out.println("Suggested sampling size : " + n);
        return (int) n;
    }
}
